﻿using System;
using System.ComponentModel;

namespace Nextensions.Basic
{
    public class OperationResult<T> : IOperationResult
    {
        public OperationResult(Exception ex)
        {
            this.Success = false;
            this.Exception = ex;
            this.Message = ex.Message;
        }

        public OperationResult(bool Success)
        {
            this.Success = Success;
        }

        public OperationResult(bool Success, T Data)
        {
            this.Success = Success;
            this.Data = Data;
        }

        public OperationResult(bool Success, T Data, string Message)
        {
            this.Success = Success;
            this.Data = Data;
            this.Message = Message;
        }

        public static OperationResult<T> Fail(string Message)
        {
            OperationResult<T> result = new OperationResult<T>(false);
            result.Message = Message;
            return result;
        }

        public bool Success
        {
            get;
            set;
        }

        [DefaultValue(null)]
        public Exception Exception
        {
            get;
            set;
        }

        [DefaultValue(null)]
        public T Data
        {
            get;
            set;
        }

        [DefaultValue("")]
        public string Message
        {
            get;
            set;
        }
    }
}
